package com.zj.easytotwitter.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.zj.easytotwitter.util.LoadingUtil;

import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * Created by ZJ
 * 基类
 */
public abstract class BaseFragment extends Fragment {
    Dialog loadingDialog;
    protected Unbinder unbinder;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflate(inflater, container);
        unbinder = ButterKnife.bind(this,rootView);
        initData();
        return rootView;
    }

    public abstract View inflate(LayoutInflater inflater, ViewGroup container);

    public abstract void initData();

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null!=unbinder)
        unbinder.unbind();
    }

    protected void showLoading(String msg) {
        loadingDialog = LoadingUtil.createLoadingDialog(getActivity(), msg);
        loadingDialog.setCanceledOnTouchOutside(false);
        loadingDialog.show();
    }

    protected void hideLoading() {
        if (loadingDialog != null)
            loadingDialog.dismiss();
        loadingDialog = null;
    }

}
